<?php

namespace app\admin\controller\user;

use app\common\controller\Backend;
use app\common\model\ScoreLog as ScoreLogModel;

/**
 * 积分明细
 *
 */
class ScoreLog extends Backend
{


    /**
     * @var ScoreLogModel
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new ScoreLogModel();
    }



    /**
     * 积分明细
     *
     */
    public function index($user_id = null)
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if (false === $this->request->isAjax()) {
            return $this->view->fetch();
        }
        //如果发送的来源是 Selectpage，则转发到 Selectpage
        if ($this->request->request('keyField')) {
            return $this->selectpage();
        }
        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
        $list = $this->model
            ->with(['user'=>function ($query) {
                $query->withField("id,username");
            }])
            ->where($where)
            ->where('user_id', $user_id)
            ->order($sort, $order)
            ->paginate($limit);

        $result = ['total' => $list->total(), 'rows' => $list->items()];
        return json($result);
    }
}
